<?php
/**
 * Restituisce un file di testo contenete il json che rappresenta una Photo
 * 
 * http://nomedominio.ex/scripts/get_json_gallery.php?id=xxx
 */
require '../config.php';
require_once SESSION_INCLUDE;
require_once DB;
require_once USER;
require_once PHOTO;
require_once PHOTO_INCLUDE;

session_start();

	$id = 0;
	
	//var_dump($_GET);

	if(!isset($_GET['id']))
	{
		echo "E' necessario selezionare una foto";
		exit();
	}
	else $id = $_GET['id'];

	$db = get_session_db($db_config);
	
	header("content-type: application/x-javascript");
	
	$photo = null;
	if(user_is_logged($db))
	{
		$photo = Photo::getPhotoFromId($db, $id);
		echo $photo->getJSON();
		
		set_session_photo($photo);
	}
	else
		echo DBEntity::getJSONFromId($db, 'gallery_photos', 'photo_id', $id);
?>